def inp():
    str1,str2 = input(),input()
    return str1,str2
    
def spl(str1,str2):
    done1,done2 = str1.split(' '),str2.split(' ')
    done2_2 = done2[:]
    done2_2.sort()
    print(done2_2)    

    return done1,done2,done2_2
    
def strint(done1,done2_2):
    for i in range(0,len(done2_2)):
        done2_2[i] = int(done2_2[i])
    for i in range(0,len(done1)):
        done1[i] = int(done1[i])

def nr(done1):
    n,r = done1[0],done1[-1]
    return n,r

def cal(done2_2,r):
    time = 0
    while len(done2_2) > 0:
        for i in range(1,min(r,len(done2_2))):
            done2_2[i] -= done2_2[0]
            print(done2_2[0])
        time += done2_2[0] * len(done2_2)
        del(done2_2[0])
    return time
        
def main():
    str1,str2 = inp()
    done1,done2,done2_2 = spl(str1,str2)
    strint(done1,done2_2)
    n,r = nr(done1)
    print(cal(done2_2,r))
    
main()